package com.easy.dfc.web;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.core.web.BaseController;
import com.easy.dfc.entity.UserPara;
import com.easy.dfc.service.UserFFFService;
import com.easy.dfc.service.UsersetService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "${apiPath}/fff")
public class UserFFFController extends BaseController {


    @Resource
    private UserFFFService userFFFService;

    @Resource
    private UsersetService usersetService;


    /**
     * 我的风车-收藏&关注&足迹统计
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FFFProductInfo", method = RequestMethod.POST)
    public Result FFFInfo(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FFFInfo(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-收藏列表
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FavoriteProduct", method = RequestMethod.POST)
    public Result FavoriteProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FavoriteProduct(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-关注列表
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FollowProduct", method = RequestMethod.POST)
    public Result FollowProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FollowProduct(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-产品足迹列表
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FootStepProduct", method = RequestMethod.POST)
    public Result FootStepProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FootStepProduct(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-收藏列表
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FavoriteFactory", method = RequestMethod.POST)
    public Result FavoriteFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FavoriteFactory(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-关注列表
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FollowFactory", method = RequestMethod.POST)
    public Result FollowFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FollowFactory(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-产品足迹列表
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FootStepFactory", method = RequestMethod.POST)
    public Result FootStepFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FootStepFactory(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 增加店铺收藏
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFavoriteFactory", method = RequestMethod.POST)
    public Result AddFavoriteFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.AddFavorite(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 增加宝贝收藏
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFavoriteProduct", method = RequestMethod.POST)
    public Result AddFavoriteProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.AddFavorite(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 增加店铺关注
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFollowFactory", method = RequestMethod.POST)
    public Result AddFollowFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.AddFollow(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 增加宝贝关注
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFollowProduct", method = RequestMethod.POST)
    public Result AddFollowProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.AddFollow(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 增加店铺足迹
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFootStepFactory", method = RequestMethod.POST)
    public Result AddFootStepFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.AddFootStep(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 增加宝贝足迹
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFootStepProduct", method = RequestMethod.POST)
    public Result AddFootStepProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.AddFootStep(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 判断店铺是否收藏
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFavoriteFactory", method = RequestMethod.POST)
    public Result HaveFavoriteFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.HaveFavorite(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 判断宝贝是否收藏
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFavoriteProduct", method = RequestMethod.POST)
    public Result HaveFavoriteProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.HaveFavorite(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 判断店铺是否关注
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFollowFactory", method = RequestMethod.POST)
    public Result HaveFollowFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.HaveFollow(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 判断宝贝是否关注
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFollowProduct", method = RequestMethod.POST)
    public Result HaveFollowProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.HaveFollow(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }


    /**
     * 删除店铺收藏
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFavoriteFactory", method = RequestMethod.POST)
    public Result DelFavoriteFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.DelFavorite(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 删除宝贝收藏
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFavoriteProduct", method = RequestMethod.POST)
    public Result DelFavoriteProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.DelFavorite(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 删除店铺关注
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFollowFactory", method = RequestMethod.POST)
    public Result DelFollowFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.DelFollow(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 删除宝贝关注
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFollowProduct", method = RequestMethod.POST)
    public Result DelFollowProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.DelFollow(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 删除店铺足迹
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFootStepFactory", method = RequestMethod.POST)
    public Result DelFootStepFactory(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.DelFootStep(para.getUserId(),String.valueOf(para.getFactoryId()),1);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 删除宝贝足迹
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFootStepProduct", method = RequestMethod.POST)
    public Result DelFootStepProduct(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.DelFootStep(para.getUserId(),para.getProductId(),2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }


    /**
     * 我的风车-收藏列表OLD
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FavoriteProductOld", method = RequestMethod.POST)
    public Result FavoriteProductOld(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FavoriteProductOld(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-关注列表
     * @param para
     * @param moDel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FollowFactoryOld", method = RequestMethod.POST)
    public Result FollowFactoryOld(@RequestBody UserPara para, Model moDel) {
        try {
            if (!usersetService.VerifyToken(para.getUserId(), para.getToken())) {
                Result rt = new Result();
                rt.setStatus(EnumConfig.S_CODE.VALID_FAILED);
                return rt;
            }
            return userFFFService.FollowFactoryOld(para);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
}
